<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<script src="js/jsencrypt.js"></script>
<script src="js/jquery.js"></script>
<script src="js/jquery.md5.js"></script>
<script src="js/base64.js"></script>

<title>form提交密码js加密页面1</title>
</head>
<body>	
	<form id="loginForm" >
		<table  style="border: 1px;color: red;border-color: green;">
			<thead>js加密密码提交及回显测试页面</thead>
			<tr>
				<td>用户名</td>
				<td>
					<input type="text" id="loginName" name="loginName">
				</td>
			</tr>
			<tr>
				<td>密码</td>
				<td>
					<input type="password" id="password1" name="password1">
				</td>
			</tr>
			<tr>
				<td>
					<!--这样可以记住上次提交的密码,方便用户回显操作?-->
					<button onclick="doLogin();">登录</button>
					<input type="hidden" name="password" id="password"/>
				</td>
			</tr>
		</table>
	</form>

</body>


<script type="text/javascript">

function doLogin() {
    var publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBWNoG5LJ3u44Gs8PWs1MaNUQQ+mOmh+9zWdzSt3ORbmfCDvU+ssW/6QTTgXvWWx7+Wzq/a4fCCQp72zSqXeVhWkTVct9Hyp/iMo5K6qOEK76z9z+tP/u99X6qazeXGVMWKkPiyZT4mKAGd/U8Mph9Z1Z5kOluA7g7heq8PPlE9wIDAQAB";
    var crypt = new JSEncrypt();
    crypt.setKey(publicKey);
    //加密密码
	var pwd1=$("#password1").val();
	var pwd=crypt.encrypt(pwd1);
    $("#password").val(pwd);
    //表单不提交
	$("#password1").attr("disabled", "true");
	//alert("原始密码:"+pwd1);
	//alert("JSEncrypt加密后密码:"+pwd);
    
    var pwd2=$.md5(pwd1);
	alert("MD5加密后密码:"+pwd2);
	
	var baseEncoder = new Base64(); 
    var pwd3=baseEncoder.encode(pwd1);
	alert("Base64加密后密码:"+pwd3);
	pwd3=baseEncoder.decode(pwd3);
	alert("Base64解密后密码:"+pwd3);
	
	//中文加密
	alert("encodeURI加密后密码:"+encodeURI("刘保"));
	alert("encodeURI解密后密码:"+decodeURI(encodeURI("刘保")));
	
    $("#loginForm").submit();
    
}

</script>

</html>
